package com.tzeng.hist;

import java.util.ArrayList;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.graphics.Typeface;

public class BaseApplication extends Application {
	public ArrayList<Activity> activitys = new ArrayList<Activity>();
	public static Typeface chineseTypeface, englishTypeface, roboto_thin,
			wendy;

	@Override
	public void onCreate() {
		super.onCreate();
		initImageLoader(getApplicationContext());
	}

	/**
	 * 初始化异步加载
	 * 
	 * @param context
	 */
	public void initImageLoader(Context context) {
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				context).threadPriority(Thread.NORM_PRIORITY - 2)
				.denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.writeDebugLogs() // Remove for release app
				.build();
		ImageLoader.getInstance().init(config);
	}

	/**
	 * 退出应用，关闭所有activity
	 */
	public void exit() {
		for (Activity activity : activitys) {
			activity.finish();
		}
	}
}